﻿package mortal.game.control
{
    import flash.utils.*;
    import frEngine.event.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.events.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.mainUI.rightTop.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class MapNavBarController extends Controller
    {
        private var _smallModule:MapNavBarModule;

        public function MapNavBarController()
        {
            return;
        }// end function

        public function get rightTopBar() : RightTopBar
        {
            return (view as MapNavBarModule).rightTopBar;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.MapPointUpdate, this.pointChangeHandler);
            FrEventDispatcher.instance.proxyAddEventListener(RolePlayer.instance, PlayerEvent.GIRD_WALK_END, this.pointChangeHandler);
            Dispatcher.addEventListener(EventName.Scene_Update, this.changeSceneHandler);
            NetDispatcher.addCmdListener(ServerCommand.SystemSettingDataGot, this.onSystemSettingUpdate);
            Dispatcher.addEventListener(EventName.SystemSettingSaved, this.onSystemSettingUpdate);
            NetDispatcher.addCmdListener(ServerCommand.RightTopNetWorkDelay, this.RightTopNetWorkDelay);
            Dispatcher.addEventListener(EventName.NetWorkPing, this.NetWorkPing);
            cache.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateLevel, this.levelUpgrade);
            return;
        }// end function

        private function onSystemSettingUpdate(param1) : void
        {
            (view as MapNavBarModule).updateBtnHideVisible();
            return;
        }// end function

        private function pointChangeHandler(param1 = null) : void
        {
            if (this._smallModule == null)
            {
                return;
            }
            this._smallModule.updateToCurrent();
            return;
        }// end function

        private function changeSceneHandler(param1 = null) : void
        {
            Dispatcher.removeEventListener(EventName.ChangeScene, this.changeSceneHandler);
            setTimeout(this.pointChangeHandler, 1200);
            return;
        }// end function

        override protected function initView() : IView
        {
            if (!this._smallModule)
            {
                this._smallModule = new MapNavBarModule();
            }
            return this._smallModule;
        }// end function

        private function RightTopNetWorkDelay(param1:Object) : void
        {
            var _loc_2:int = 0;
            if (cache.rightTop.networkPingArray.length > 0)
            {
                _loc_2 = int(param1);
                cache.rightTop.Delay = getTimer() - _loc_2;
                cache.rightTop.networkPingArray.length = 0;
                this.rightTopBar.netWorkPanel.refresh();
            }
            return;
        }// end function

        private function NetWorkPing(event:DataEvent) : void
        {
            GameProxy.rightTop.testNet(event.data.toString());
            return;
        }// end function

        private function levelUpgrade(param1) : void
        {
            this.rightTopBar.checkOpenLevel();
            return;
        }// end function

        private function hasRewardOrNot(event:DataEvent) : void
        {
            var _loc_4:Array = null;
            var _loc_5:Boolean = false;
            var _loc_2:* = event.data as Array;
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = _loc_2[0];
            if (_loc_3 == "signUp")
            {
                _loc_4 = [_loc_2[1], _loc_2[2]];
                _loc_5 = cache.signUp.updateSignUpHasReward(_loc_4);
                this.rightTopBar.blinkBtn("signUp", _loc_5);
            }
            return;
        }// end function

    }
}
